package com.zlq.ajaxjson.test;

import com.zlq.ajaxjson.entity.User;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class test2 {
    public static void main(String[] args) {
        String jsonString = "{\"name\":\"李云鹏\",\"age\":999,\"address\":[\"千年王八，万年鳖\",\"李晕鹏\"]}";
        JSONObject json = JSONObject.fromObject(jsonString);
        String name = json.getString("name");
        System.out.println(name);
        int age = json.getInt("age");
        System.out.println(age);
        JSONArray address = json.getJSONArray("address");
        for (int i = 0; i < address.size(); i++) {
            String str = address.getString(i);
            System.out.println(str);
        }

//        String jsonStr = "{\"id\":2,\"name\":\"李云鹏\",\"sex\":\"男\",\"number\":7777}";
//        JSONObject js = JSONObject.fromObject(jsonStr);
//        User o = (User) JSONObject.toBean(js, User.class);
//        System.out.println(o);
        String jsonS = "[2,\"李云鹏\",\"男\",7777]";
        JSONArray jsonArray = JSONArray.fromObject(jsonS);
        int anInt = jsonArray.getInt(0);
        System.out.println(anInt);
        String string = jsonArray.getString(1);
        System.out.println(string);
        int anInt1 = jsonArray.getInt(3);
        System.out.println(anInt1);


    }
}
